<?
	include "./includes/messages.inc.php";
	include "./includes/config.inc.php";
	include "./includes/prepend.inc.php";

	#// If user is not logged in redirect to login page
	if(!isset($_SESSION["PHPAUCTION_LOGGED_IN"]))
	{
		header("Location: user_login.php");
		exit;
	}

	// Submit
	if ($_POST)
	{
	
		// Insert draft transaction
		$sql = "insert into PHPAUCTIONW_transactions set dtpaid = NOW(), pamount = '".$_POST['amount']."', gate='".$_POST['gate']."', userid = '".$_SESSION["PHPAUCTION_LOGGED_IN"]."'";
		mysql_query($sql) or die(mysql_error());
		$orderid = mysql_insert_id();
		
		// Save transaction stuff to session
		$_SESSION["amount"] = $_POST['amount'];
		$_SESSION["orderid"] = $orderid;
		$_SESSION["gate"] = $_POST['gate'];
		
		header("Location: paygate.php");
	}
	
	// Get balance
	$rs1 = mysql_query("select balance from PHPAUCTION_users where id = '".$_SESSION["PHPAUCTION_LOGGED_IN"]."'") or die(mysql_error());
	$rowt = mysql_fetch_assoc($rs1);
	$total1 = (float)$rowt['balance'];
	
	// Total proccessed
	$rs1 = mysql_query("select sum(pamount) as s from PHPAUCTIONW_transactions where userid = '".$_SESSION["PHPAUCTION_LOGGED_IN"]."' and ispaid = 1") or die(mysql_error());
	$rowt = mysql_fetch_assoc($rs1);
	$totalin = (float)$rowt['s'];
	
	$totalout = $totalin - $total1;
	
	
	// Total proccessed
	$rsp = mysql_query("select * from PHPAUCTIONW_transactions where userid = '".$_SESSION["PHPAUCTION_LOGGED_IN"]."' and ispaid = 1") or die(mysql_error());
	$rspt = mysql_num_rows($rsp);
	
	$gato = array
	(
		"2co" => "2Checkout",
		"pp" => "PayPal",
		"storm" => "StormPay"
	);
	

	include "header.php";
	include "./templates/template_yourmoney_php.html";
	include "footer.php";
	
?>